function getSetting() {
  return JSON.parse(localStorage.getItem('setting'));
}
export function getSettingbyKey(key) {
  const { sValue } = getSetting().filter((item) => item.sKey === key)[0];
  if (sValue) {
    return sValue;
  }

  return '';
}
export function getSettingbyincludes(key) {
  // 使用 filter 方法找到所有 sKey 包含 key 的项
  const matchedItems = getSetting().filter((item) => item.sKey.includes(key));

  // 使用 map 方法从匹配的项中提取 sValue
  const matchedValues = matchedItems.map((item) => item.sValue);

  // 返回包含所有匹配 sValue 的数组
  return matchedValues;
}
function generateUniqueStringWithUserIdAndTimestamp(userId, length) {
  const timestamp = new Date().getTime().toString();
  let uniqueString = userId + timestamp;
  const randomString = Math.random()
    .toString(36)
    .substr(2, length - uniqueString.length);
  uniqueString += randomString;
  console.log('uniqueString', uniqueString);
  return uniqueString;
}
export function getOrSetLocalStorage(key) {
  const user = JSON.parse(localStorage.getItem('userinfo'));
  // 检查localStorage中是否存在指定的key
  const defaultValue = generateUniqueStringWithUserIdAndTimestamp(user.id, 24);

  if (localStorage.getItem(key) === '') {
    // 如果不存在，使用defaultValue设置项
    localStorage.setItem(key, defaultValue);
    return defaultValue;
  } else {
    // 如果存在，读取并返回该项的值
    return localStorage.getItem(key);
  }
}

